package com.example.server.controller;

import com.example.server.domain.Students;
import com.example.server.service.StudentsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Controller
//@CrossOrigin(origins = "*",allowCredentials = "true",allowedHeaders = "*",methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.DELETE,RequestMethod.PUT,RequestMethod.OPTIONS})
@RequestMapping("/students")
public class StudentsController {
    private final StudentsService studentsService;

    public StudentsController(StudentsService studentsService) {
        this.studentsService = studentsService;
    }


    @RequestMapping("/upload")
    @ResponseBody
    public String uploadFile(MultipartFile file) {
        return studentsService.uploadFile(file);
    }
    @RequestMapping("/create")
    @ResponseBody
    public void createStudent(@RequestBody Students students) {
        studentsService.createStudent(students);
    }
    @RequestMapping("/delete")
    @ResponseBody
    public void deleteStudent(Long id) {
        studentsService.deleteStudent(id);
    }
    @RequestMapping("/querybyid")
    @ResponseBody
    public Students getStudentById(Long id) {
        return studentsService.getStudentById(id);
    }
    @RequestMapping("/update")
    @ResponseBody
    public void updateStudent(@RequestBody Students students) {
         studentsService.updateStudent(students);
    }
    @RequestMapping("/queryall")
    @ResponseBody
    public List<Students> getAllStudents() {
        return studentsService.getAllStudents();
    }

    @RequestMapping("/querylike")
    @ResponseBody
    public List<Students> querylike(String sname) {
        return studentsService.querylike(sname);
    }
}
